/**
  * Author: Mei
  * Date: 2020-12-07 11:44
  * Description: 
  *
  */
#include <iostream>
#include <utility>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <map>

using namespace std;

int main() {
    pair<string, int> myPair("hello", 5);
    pair<string, int> myOtherPair;
    auto autoPair = make_pair("hello", 5);
    myOtherPair.first = "world";
    myOtherPair.second = 6;
    cout << autoPair.first << "," << autoPair.second << endl;


    //map
    map<string, int> m = {
            {"zhangsan", 123},
            {"li",       434},
            {"li1",      334}
    };
    for (const auto &p : m) {
        cout << p.first << "," << p.second << endl;
    }
    map<string, int> m1;
    auto ret = m1.insert({"wanwu", 234});
    pair<map<string, int>::iterator, bool> ret1 = m1.insert({"wanwu", 234});
    cout << ret1.second << endl;

    map<int, int> dataMap;
    dataMap[2] = 12;
    dataMap[4] = 11;
    dataMap[3] = 17;
    dataMap.insert({6, 32});
    dataMap.insert(make_pair(7, 22));
    dataMap.insert(pair<int, int>(8, 20));
    auto it = dataMap.find(2);
    auto it1 = dataMap[5]; //[]没有找到就自己创建
    cout << it1 << endl;
    if (it != dataMap.end()) {
        cout << it->second << endl;
    }
    cout << "------------" << endl;
    for (const auto &p : dataMap) {
        cout << p.first << "," << p.second << endl;
    }
    cout << "------------" << endl;
    multimap<int, int> muMap;
    muMap.insert(make_pair(12, 19));
    muMap.insert(make_pair(12, 16));
    muMap.insert(make_pair(12, 18));
    muMap.insert(make_pair(12, 111));
    muMap.insert(make_pair(12, 14));
    muMap.insert(make_pair(11, 12));
    for (const auto &p : muMap) {
        cout << p.first << ", " << p.second << endl;
    }
    cout << "------------" << endl;
    //使用lower_bound 和 upper_bound
    auto iter = muMap.lower_bound(12);
    auto end = muMap.upper_bound(12);
    while (iter != end) {
        cout << iter->first << ", " << iter->second << endl;
        ++iter;
    }
    cout << "------------" << endl;
    //使用equal_range()比使用lower_bound()和upper_bound()更高效
    auto range = muMap.equal_range(12); //获得具有给定键的元素对应的iterator
    auto iter1 = range.first;
    auto end1 = range.second;
    while (iter1 != end1) {
        cout << iter1->first << ", " << iter1->second << endl;
        ++iter1;
    }


    return 0;
}